package cn.wolfcode.wolf2w.business.controller;

import cn.wolfcode.wolf2w.business.api.domain.StrategyCatalog;
import cn.wolfcode.wolf2w.business.service.IStrategyCatalogService;
import cn.wolfcode.wolf2w.common.core.constant.SecurityConstants;
import cn.wolfcode.wolf2w.common.core.domain.R;
import cn.wolfcode.wolf2w.common.security.annotation.InnerAuth;
import cn.wolfcode.wolf2w.business.api.domain.Strategy;
import cn.wolfcode.wolf2w.business.query.StrategyQuery;
import cn.wolfcode.wolf2w.business.service.IStrategyService;
import cn.wolfcode.wolf2w.common.security.annotation.RequiresLogin;
import com.baomidou.mybatisplus.core.metadata.IPage;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;
import java.util.Map;

/**
 * 攻略 Controller
 * 
 * @author fang
 * @date 2024-09-27
 */
@RestController
@RequestMapping("strategies")
public class StrategyController {
    @Autowired
    private IStrategyService strategyService;

    @Autowired
    private IStrategyCatalogService strategyCatalogService;


    /**
     * 攻略详情
     */
    @GetMapping("/detail/{id}")
    public R<Strategy> detail(@PathVariable("id") Long id) {
        Strategy strategy = strategyService.selectById(id);
        return R.ok(strategy);
    }

    @PostMapping("/viewnumIncr")
    public R<?> viewnumIncr(Long sid){
        Map<String,Object> map = strategyService.viewnumIncr(sid);
        return R.ok(map);
    }

    @PostMapping("/replynumIncr")
    public R<?> replynumIncr(Long sid){
        Map<String,Object> map = strategyService.replynumIncr(sid);
        return R.ok(map);
    }

    //必须登录才能加一
    @RequiresLogin
    @PostMapping("/favor")
    public R<?> favor(Long sid){
        Map<String,Object> map = strategyService.favornumIncr(sid);
        return R.ok(map);
    }

    @RequiresLogin
    @PostMapping("/thumbsup")
    public R<?> thumbsup(Long sid){
        Map<String,Object> map = strategyService.thumbsubIncr(sid);
        return R.ok(map);
    }

    /**
     * 攻略 列表
     */
    @GetMapping("/query")
    public R<IPage<Strategy>> query(StrategyQuery qo) {
        IPage<Strategy> page = strategyService.queryPage(qo);
        return R.ok(page);
    }

    @GetMapping("/viewnnumTop3")
    public R<List<Strategy>> viewnnumTop3(Long destId){
        List<Strategy> list =  strategyService.queryViewnumTop3(destId);
        return R.ok(list);

    }

    @GetMapping("/catalogList")
    public R<List<StrategyCatalog>> catalogList(Long destId){
        List<StrategyCatalog> list =  strategyCatalogService.queryCatalogList(destId);
        return R.ok(list);

    }







    /*****************************************对外暴露Fegin接口**********************************************/
    /**
     * Feign 接口
     */
    @GetMapping("/feign/list")
    public R<List<Strategy>> feignList() {
        return R.ok(strategyService.list());
    }
    @InnerAuth
    @GetMapping("/feign/{id}")
    public R<Strategy> feignGet(@PathVariable Long id) {
        return R.ok(strategyService.getById(id));
    }
    @GetMapping("/feign/statisHashPersistence")
    public R<?>statisHashPersistence(@RequestHeader(SecurityConstants.FROM_SOURCE) String source){
        strategyService.statisHashPersistence();
        return R.ok();
    }



}
